
const {ccclass, property} = cc._decorator;

@ccclass
export default class bh_toast extends cc.Component {

    @property(cc.Label)
    txt: cc.Label = null;


    show(txt: string, parent: cc.Node, startY: number = 0) {
        this.txt.string = txt;
        this.node.parent = parent;
        this.node.y = startY - 100;
        this.node.opacity = 10;
        this.node.zIndex = 3000;
        cc.tween(this.node).to(0.3, { y: startY + 100, opacity: 255 }).to(1.2, { y: startY + 120, opacity: 255 }).to(0.3, { y: startY + 200, opacity: 0 }).call(() => {
            this.node.destroy();
        }).start();

        this.scheduleOnce(()=>{
            if (this.node && this.node.isValid) {
                this.node.destroy();
            }
        },1);
    }

    // public static showToast(txt: string, parent: cc.Node, startY: number = 0) {
    //     const bundle = cc.assetManager.getBundle('privacy');
    //     bundle.load('bh_toast', cc.Prefab, (err, prefab: cc.Prefab) => {
    //         if (err) {
    //             console.error(err);
    //             return;
    //         }
    //         const newNode: cc.Node = cc.instantiate(prefab);
    //         newNode.getComponent(bh_toast).show(txt, parent, startY);
    //     });
    // }
}
